<?php echo Modules::run( 'partial/header/index'); ?>
<div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
</div>

<?php if ($error_warning) { ?>
    <!--  start message-red -->
    <div id="message-red">
        <table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td class="red-left">Error. <?php echo $error_warning; ?></td>
                <td class="red-right"><a class="close-red"><img src="<?php echo base_url(); ?>includes/images/table/icon_close_red.gif"   alt="" /></a></td>
            </tr>
        </table>
    </div>
    <!--  end message-red -->
<?php } ?>
<?php if ($success) { ?>
    <!--  start message-green -->
    <div id="message-green">
        <table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td class="green-left"><?php echo $success; ?></td>
                <td class="green-right"><a class="close-green"><img src="<?php echo base_url(); ?>includes/images/table/icon_close_green.gif"   alt="" /></a></td>
            </tr>
        </table>
    </div>
    <!--  end message-green -->
<?php } ?>
  

<div class="box">
    <div class="heading">
      <h1><img src="<?php echo base_url(); ?>includes/images/icons/category.png" alt="Category" /> <?php echo $heading_title; ?></h1>
      
    </div>
    <div class="content">

		<script type="text/javascript">
        $(function(){
                    $('#test').datagrid({
                        title:'<?php echo $heading_title ?>',
                        //iconCls:'icon-save',
                        width:'80%',
                        height:'400',
                        method:'post',
                        nowrap: false,
                        striped: true,
                        //collapsible:true,
                        url: '<?php echo $datagrid; ?>',
                        sortName: 'lft',
                        sortOrder: 'asc',
                        remoteSort: true,
                        fitColumns:true,
                        idField:'category_id',
                        frozenColumns:[[
							{field:'category_id',checkbox:true}
							
						]],
                        columns:[[
                            
                            {field:'name',title:'<?php echo $column_name; ?>',width:180,sortable:true,
                                sorter:function(a,b){
                                    return (a>b?1:-1);
                                }
                            },
                            
                            
                            
                            {field:'sort_order',title:'<?php echo $column_sort_order; ?>',width:100,sortable:true,
                                sorter:function(a,b){
                                    return (a>b?1:-1);
                                }
                            },
                            
							{field:'status',title:'<?php echo $column_status; ?>',width:100,sortable:true,
                                sorter:function(a,b){
                                    return (a>b?1:-1);
                                }
                            },
							{field:'opt',title:'<?php echo $column_action; ?>',width:100,align:'center',
								formatter:function(value,rec){
									return '<a href="<?php echo $edit; ?>/'+rec.category_id+'"  ><?php echo $button_edit; ?></a>';
								}
							}
                            
                            
                            
                        ]],
                        
                        pagination:true,
                        rownumbers:true,
                        showFooter:false,
                        
                        toolbar:[{
							id:'btnadd',
							text:'<a href ="<?php echo $insert; ?>"><?php echo $button_insert; ?></a>',
							iconCls:'icon-add'
							
						},'-',{
							id:'btndelete',
							text:'<span style="color:red"><?php echo $button_delete; ?></span>',
							iconCls:'edit-remove',
							handler:function(){
								
								var ids = [];
								var rows = $('#test').datagrid('getSelections');
								for(var i=0;i<rows.length;i++){
									ids.push(rows[i].category_id);
								}
								//alert(ids.join(':'));
								var uu = ids.join('-');
								if(uu == "")
								{
									alert('<?php echo $message_selections; ?>');
								}
								else
								{
									$.messager.confirm('My Title', 'Are you confirm to delete these categories?', function(r){
										if (r){
											clickDelete(uu);
										}
										else
										{
											return false;
										}
									});
									
								}
							}
						}]
                        
                        
                    });
                    
                    var p = $('#test').datagrid('getPager');
                    if (p){
                        $(p).pagination({
                            onBeforeRefresh:function(){
                               // alert('before refresh');
                            }
                        });
                    }
                    
                    //$('#test').datagrid('fitColumns');
                    
        
        
                
                });
				
		
				
		function clickDelete(mid)
		{
			var data = 'category_ids='+mid;
			
			$.ajax({
				type:"POST",
				url:'<?php echo $delete; ?>',
				data: data,
				success : function(data) {
					if (data == "succ") {
						$.messager.alert('System Info', 'Delete Successfully!', 'info');
								
						$('#test').datagrid('reload');
						$('#test').datagrid('clearSelections');	
					} else {
						$.messager.alert('System Info', data, 'error');
					}
				}
			});
		}
                
   
                
        </script>
        
        <div style="padding:5px;">    
        
            
            <table id="test">
            
            </table>
        </div>      
      
      
    </div>
  </div>
 
<?php //$this->load->view("common/footer"); ?>
 
<?php /*?><?php echo $footer; ?><?php */?>
<?php echo Modules::run( 'partial/footer/index'); ?>